﻿
$(function(){
	$.cookie('return_statue',$.cookie('statue'));
	var singleTaskId = $('#singleTaskId').val();
	getInfoBySingleTaskId(singleTaskId);
	
	//工单流转内容
	getWorkFlow(singleTaskId);
	
	// 日期框
	laydate.render({
	    elem: '#applicationDate', //指定元素
	    type: 'datetime',
	    min : 0
	  });
	laydate.render({
	    elem: '#pushTime', //指定元素
	    type: 'datetime',
	    min : 0
	  });
//      laydate.render({
//        elem: '#firstTime2', //指定元素
//        min: firstTime1,
//        type: 'datetime'
//      });
	
	var registerProvinceHtml = provinceSelectHtml("registerProvince"); //获取省id
	$("#registerProvince").html(registerProvinceHtml);
	
	valid();
});

function getWorkFlow(singleTaskId){
	$.ajax({
		type : "POST",
		url : "evalTaskFlow/getBySingleTaskId",
		data : {
			"singleTaskId" : singleTaskId
		},
		traditional: true,
		dataType : "json",
		success : function(data) {
			if (data.flag) {
				var datas = data.datas;
				$("#work_flow").empty();
				var str = "";
				for(var i = 0 ; i < datas.length ; i++){
					var data = datas[i];
					str += "<tr><td>"+data['userName']+"</td><td>"+data['handleTime']+"</td><td>"+data['statue']+"</td><td title="+filter(data['reason'])+">"+filter(data['reason'])+"</td></tr>";
				}
				$("#work_flow").append(str);
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function htmlCss(){
	var backViewType = $('#backViewType').val();
	if(backViewType == 1){ // 企业侧查看
		var statue = $('#statue').val();
		//修改 6-评测中  7-测试通过  8-测试不通过 查看需要看申请表单的内容
		if(statue == 3 || statue == 5 || statue2 == 6 || statue2 == 7 || statue2 == 8){ // 按钮查看时，所有文本框禁用
			$("#queryForm").find("input").each(function(){
				$(this).attr("disabled", "disabled");
			});
			// 按钮显示
			$('button[name="btn_1"]').attr("style", "display:none");
			$('button[name="btn_2"]').attr("style", "display:none");
			$('button[name="btn_3"]').attr("style", "display:none");
		} else {
			$('button[name="btn_1"]').removeAttr("style");
			$('button[name="btn_2"]').removeAttr("style");
			$('button[name="btn_3"]').removeAttr("style");
		}
		// 核实后需打印
		if(statue == 5){
			$('button[name="btn_9"]').removeAttr("style");
		}
	} else if(backViewType == 2){ // 管局查看
		$("#queryForm").find("input").each(function(){
			$(this).attr("disabled", "disabled");
		});
		$("input[id$=_btn]").each(function(){
			$(this).attr("style", "display:none");
		});
		// 按钮显示
		$('button[name="btn_1"]').attr("style", "display:none");
		$('button[name="btn_2"]').attr("style", "display:none");
		$('button[name="btn_3"]').attr("style", "display:none");
		
		var statue = $('#statue').val();
		if(statue == 1){ // 
			$('button[name="btn_4"]').removeAttr("style");
			$('button[name="btn_5"]').removeAttr("style");
		} else if(statue == 2){
			// 按钮显示
			$('button[name="btn_7"]').removeAttr("style");
			$('button[name="btn_8"]').removeAttr("style");
			// 核实后需打印
			$('button[name="btn_9"]').removeAttr("style");
		} 
	}
}

function getInfoBySingleTaskId(singleTaskId){
//	var eType = $('#eType').val();
	var userId = $('#userId').val();
	var backViewType = $('#backViewType').val();
	var statue = $('#statue').val();
	$.ajax({
		type : "POST",
		url : "evalApplication/getCdnAudit",
		data : {
			'singleTaskId':singleTaskId, 
			'backViewType': backViewType,
			'statue': statue,
//			'eType': eType, 
			'userId': userId,
			'form_number' : $("#form_number").val()
		},
		traditional: true,
		dataType : "json",
		success : function(data) {
			if (data.flag) {
				var cnameData = data.cnameData;
				/*if(null != cnameData){
					setCnameBody(cnameData);
				}*/
				var nodeData = data.nodeData;
				if(null != nodeData){
					setNodeBody(nodeData);
				}
				var coverData = data.coverData;
				if(null != coverData){
					setCoverBody(coverData);
				}
				
				var fileData = data.fileData;
				if(null != fileData){
					setFileBody(fileData);
				}
				
				var registerProvince = data.data.registerProvince;
				citysSelectByProvinceNameHtml(registerProvince,3);
				
				fillFormData('#queryForm', data.data);
				htmlCss();
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function setFileBody(fileData){
	var backViewType = $('#backViewType').val();
	var fileHtml = "";
	if(backViewType == 2){ // 查看
		for(var i=0; i<fileData.length; i++){
			var hrefUrl = 'evalApplication/fileDownLoad?fileId=' + fileData[i].id;
			fileHtml = '<a href="'+hrefUrl+'">'+fileData[i].name+'</a>&nbsp;&nbsp;&nbsp;';
			$('#filesBox_'+(fileData[i].type - 1)).append(fileHtml);
			
			var num = $('#filesBox_'+(fileData[i].type - 1)+'_fileNum').val();
			$('#filesBox_'+(fileData[i].type - 1)+'_fileNum').val(++num);
		}
		
	} else {
		for(var i=0; i<fileData.length; i++){
			fileHtml = '<input type="text"style="width:120px;" readonly value="'+fileData[i].name+'">&nbsp;&nbsp;&nbsp;';
			$('#filesBox_'+(fileData[i].type - 1)).append(fileHtml);
			
			var num = $('#filesBox_'+(fileData[i].type - 1)+'_fileNum').val();
			$('#filesBox_'+(fileData[i].type - 1)+'_fileNum').val(++num);
		}
	}
}

function setCoverBody(coverData){
	if(coverData && coverData.length > 0){
		$('#coverBody').html('');
		for(var i=0; i<coverData.length; i++){
			addTableTr('cover', coverData[i]);
		}
	}
}

// 自动添加节点值
function setNodeBody(nodeData){
	if(nodeData && nodeData.length > 0){
		$('#nodeBody').html('');
		for(var i=0; i<nodeData.length; i++){
			addTableTr('node', nodeData[i]);
		}
	}
}

/**
 * 保存或暂保存
 * @param type
 */
function saveApplication(type){
	$('#saveType').val(type);
	if(type == 2){
		var notEmpty = true;
		$('input[notEmpty]').each(function(){
			var name = $(this).attr("name");
			var type = $(this).attr("type");
			
			var check_name = $(this).attr("notEmpty-value");
			var check_value = $('input[name="'+name+'"]').val();
			var reg = "";
			if(check_name == '邮编'){
				reg = /^[0-9]{6}$/;
				notEmpty = check_field(reg,check_value,check_name);
			}else if(check_name == '固定电话'){
				reg = /^(\d3,4|\d{3,4}-)?\d{7,8}$/;
				notEmpty = check_field(reg,check_value,check_name);
			}else if(check_name == '传真'){
				reg = /^(\d{3,4}-)?\d{7,8}$/;
				notEmpty = check_field(reg,check_value,check_name);
			}else if(check_name == '移动电话'){
				reg = /^1[34578]\d{9}$/;
				notEmpty = check_field(reg,check_value,check_name);
			}else if(check_name == '电子邮件'){
				reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
				notEmpty = check_field(reg,check_value,check_name);
			}
			if(!notEmpty){
				return false;
			}
			
			if(type == 'radio' && $('input:radio[name="'+name+'"]:checked').val() == 0){
				layer.alert($(this).attr("notEmpty-value")+"不能为空！", {icon : 3,offset: '100px'});
				notEmpty = false;
				return false;
			} else if(type == 'text' && ($('input[name="'+name+'"]').val() == '' || $('input[name="'+name+'"]').val() == 0)){
				layer.alert($(this).attr("notEmpty-value")+"不能为空！", {icon : 3,offset: '100px'});
				notEmpty =  false;
				return false;
			}
		})
		
		if(!notEmpty){
			return false;
		}
		
		var gbps = $('input[name="gbps"]').val();
		//申请表中链路带宽不能大于系统处理能力，可小于或等于
		var handleInfo = $('input[name="handleInfo"]').val();
		if(parseInt(handleInfo) < parseInt(gbps)){
			layer.alert("链路总带宽不能大于系统处理能力！", {icon : 3,offset: '100px'});
			notEmpty = false;
			return false;
		}
		
		var quertForm1 = $('#quertForm1').find('input[name="upFiles"]').length;//准备上传
		var filesBox_0 = $("#filesBox_0").children().length;//已经上传
		var quertForm2 = $('#quertForm2').find('input[name="upFiles"]').length;
		var filesBox_1 = $("#filesBox_1").children().length;
		var quertForm3 = $('#quertForm3').find('input[name="upFiles"]').length;
		var filesBox_2 = $("#filesBox_2").children().length;
		var quertForm4 = $('#quertForm4').find('input[name="upFiles"]').length;
		var filesBox_3 = $("#filesBox_3").children().length;
		if((quertForm1 == 0 && filesBox_0 == 0) || (quertForm2 == 0 && filesBox_1 == 0) || (quertForm3 == 0 && filesBox_2 == 0) || (quertForm4 == 0 && filesBox_3 == 0)){
			layer.alert("申请评测相关材料除其他材料外必须上传！", {icon : 3,offset: '100px'});
			notEmpty =  false;
			return false;
		}
		
		if(!notEmpty){
			return false;
		}
	}
	uploadFiles();
	$.ajax({
		type : "POST",
		url : "evalApplication/addOrUpdate",
		data : $("#queryForm").serialize(),
		traditional: true,
		dataType : "json",
		success : function(data) {
			//uploadFiles();
			if (data.flag) {
				if(type != 1){//暂存页面不跳转
					backView();
				}
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
	
}

/**
 * form 数据填充
 */
function fillFormData(form, obj) {
	var formEL = $(form);
	$.each(obj, function(index, item) {
	   formEL.find("[name=" + index + "]").val(item);
	});
}

/**
 * 返回按钮
 * @returns
 */
function backView(){
	var backViewType = $('#backViewType').val();
	var userId = $('#userId').val();
	if(backViewType == 1){ // 企业侧
		window.location.replace("singleTask?userId="+userId);
	} else if(backViewType == 2){ //管局侧
//		window.location.replace("evalTaskAudit?userId="+userId);
		window.location.replace("evalTaskAudit");
	}
}

/**
 * 核实
 */
function verify(){
	var singleTaskId = $('#singleTaskId').val();
	updateStatue(singleTaskId, 2, '', '核实');
}

/**
 * 开始评测
 * @param singleTaskId
 * @param statue
 * @param reason
 */
function beginEval(){
	var singleTaskId = $('#singleTaskId').val();
	updateStatue(singleTaskId, 4, '', '开始评测');
}

function updateStatue(singleTaskId, statue, reason, btnName){
	$.ajax({
		type : "POST",
		url : "evalApplication/updateStatue",
		data : {
			'singleTaskId': singleTaskId,
			'statue': statue,
			'reason': reason,
			'btnName': btnName
		},
		traditional: true,
		dataType : "json",
		success : function(data) {
			if (data.flag) {
				backView();
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

/**
 * 退回
 * @returns
 */
function reject(){
	var singleTaskId = $('#singleTaskId').val();
	var reason = $('#reason').val();
	updateStatue(singleTaskId, 3, reason, '退回');
}
/**
 * 撤销核实
 */
function reject6(){
	var singleTaskId = $('#singleTaskId').val();
	var reason = $('#reason6').val();
	updateStatue(singleTaskId, 3, reason, '撤销核实');
}

function downloadtemplate(){
	$.ajax({
		type : "POST",
		url : "evalApplication/downloadtemplate",
		data : {
			'name': "EVAL_TEMPLATE_CDN"
		},
		traditional: true,
		dataType : "json",
		success : function(data) {
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

/**
 * 
 * @param n
 */
function setFilesBody(n){
	var obj = $('#filesBox_'+n+"_btn");
	var btnValue = obj.attr('btn-value');
	++btnValue;
	var html = '<span id="fileBody_'+n+btnValue+'"><input type="file" name="upFiles" id="upFile_'+n+btnValue+'" style="display:none;" onchange="getFile('+n+','+btnValue+')"/>'
		+'<input type="text"style="width:120px;" class="easyui-validatebox input-text" readonly="readonly" id="fileName_'+n+btnValue+'"/><font color="red" onclick="delFile('+n+','+btnValue+')" style="cursor:pointer;padding-right:10px;">X</font></span>';
	
	obj.attr('btn-value',btnValue);
	$('#filesBox_'+n).append(html);
	
	$('#upFile_'+n+btnValue).click();
}

/**
 * 
 * @param n1 当前 文件 box 坐标
 * @param n 当前文件 坐标
 */
function getFile(n1,n){
	var fileUrl = $('#upFile_'+n1+n).val();
	if(fileUrl){
		var reportName = fileUrl.substring(fileUrl.lastIndexOf('\\')+1, fileUrl.length) ;
		$("#fileName_"+n1+n).val(reportName);
		
		var fileNum = $('#filesBox_'+n1+'_fileNum').val();
		if(fileNum != ''){
			$('#filesBox_'+n1+'_fileNum').val(++fileNum);
		}
	} 
}

/**
 * 
 * @param n1 当前 文件 box 坐标
 * @param n 当前文件 坐标
 */
function delFile(n1,n){
	$("#fileBody_"+n1+n).remove();
	var fileNum = $('#filesBox_'+n1+'_fileNum').val();
	if(fileNum != '' && fileNum != 0){
		$('#filesBox_'+n1+'_fileNum').val(--fileNum);
	}
}

/**
 * 所有附件上传
 */
function uploadFiles(){
	if($('#quertForm1').find('input[name="upFiles"]').length > 0){
		upload('quertForm1');
	}
	if($('#quertForm2').find('input[name="upFiles"]').length > 0){
		upload('quertForm2');
	}
	if($('#quertForm3').find('input[name="upFiles"]').length > 0){
		upload('quertForm3');
	}
	if($('#quertForm4').find('input[name="upFiles"]').length > 0){
		upload('quertForm4');
	}
	if($('#quertForm5').find('input[name="upFiles"]').length > 0){
		upload('quertForm5');
	}
}

function upload(formId) {
	var singleTaskId = $('#singleTaskId').val();
	var url = "evalApplication/fileUpload";
	var options = {
		url : url,
		type : 'post',
		data : {
			'singleTaskId' : singleTaskId
		},
		dataType : "html",
		success : function(result) {

		},
		error : function(result) {
		}
	};
	$("#" + formId).ajaxSubmit(options);
}

function addTableTr(type, data){
	var html = '';
	var tbodyId = 'nodeBody';
	var num = parseInt($('#'+tbodyId).attr('id-value'));
	var trBodyId = 'node_body_tr_' + num;
	var trBodyTdId = 'node_body_tr_td_';  // id排序
	
	if(type == 'cover'){
		tbodyId = 'coverBody';
		num = parseInt($('#'+tbodyId).attr('id-value'));
		trBodyId = 'cover_body_tr_' + num;
		trBodyTdId = 'cover_body_tr_td_';
		if(data != null){
			html += '<tr id="'+trBodyId+'">'
			+ '<td id="cover_body_tr_td_'+num+'">'+(num+1)+'</td>'
			+ '<td>'
			+ '<select class="form-control text-box" name="coverList['+num+'].coverName" notEmpty notEmpty-value="覆盖业务链路类型/名称" value="'+data.coverName+'">'
			+ '<option value=""></option>';
			
			var coverName = data.coverName;
			if(coverName == '联通'){
				html += '<option value="联通" selected>联通</option>'
					 + '<option value="移动" >移动</option>'
					 + '<option value="电信" >电信</option>'
					 + '<option value="其他" >其他</option>';
			} else if(coverName == '移动'){
				html += '<option value="联通">联通</option>'
					 + '<option value="移动" selected>移动</option>'
					 + '<option value="电信" >电信</option>'
					 + '<option value="其他" >其他</option>';
			} else if(coverName == '电信'){
				html += '<option value="联通">联通</option>'
					 + '<option value="移动">移动</option>'
					 + '<option value="电信" selected>电信</option>'
					 + '<option value="其他">其他</option>';
			} else if(coverName == '其他'){
				html += '<option value="联通">联通</option>'
					 + '<option value="移动">移动</option>'
					 + '<option value="电信">电信</option>'
					 + '<option value="其他" selected>其他</option>';
			}
			html += '</select>'
		//	+ '<input type="text" class="form-control input-sm" name="coverList['+num+'].coverName" notEmpty notEmpty-value="覆盖业务链路类型/名称" value="'+data.coverName+'"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="coverList['+num+'].gbps" onblur="getSum(this.value)" notEmpty notEmpty-value="链路带宽(Gbps)" value="'+data.gbps+'"/>'
			+ '</td>';
			
			var coverMode = data.coverMode;
			if(coverMode == 1){
				html += '<td>'
				+ '<div class="form-group">'
				+ '<label class="radio-inline">'
				+ '<input type="radio" name="coverList['+num+'].coverMode" value="0" style="display:none;" checked="checked" notEmpty notEmpty-value="覆盖方式">'
				+ '<input type="radio" name="coverList['+num+'].coverMode" value="1" checked="checked"> 并接'
				+ '</label>'
				+ '<label class="radio-inline">'
				+ '<input type="radio" name="coverList['+num+'].coverMode" value="2"> 串接'
				+ '</label>'
				+ '</div>'
				+ '</td>';
			} else if(coverMode == 2) {
				html += '<td>'
					+ '<div class="form-group">'
					+ '<label class="radio-inline">'
					+ '<input type="radio" name="coverList['+num+'].coverMode" value="0" style="display:none;" checked="checked" notEmpty notEmpty-value="覆盖方式">'
					+ '<input type="radio" name="coverList['+num+'].coverMode" value="1"> 并接'
					+ '</label>'
					+ '<label class="radio-inline">'
					+ '<input type="radio" name="coverList['+num+'].coverMode" value="2" checked="checked"> 串接'
					+ '</label>'
					+ '</div>'
					+ '</td>';
			}
			html += '<td style="cursor:pointer" onclick="delTableTr('+trBodyId+')">'
			+ '<font style="color:red;" size="5">-</font>'
			+ '</td>'
			+ '</tr>';
		} else {
			html += '<tr id="'+trBodyId+'">'
			+ '<td id="cover_body_tr_td_'+num+'">'+(num+1)+'</td>'
			+ '<td>'
			+ '<select class="form-control text-box" name="coverList['+num+'].coverName" notEmpty notEmpty-value="覆盖业务链路类型/名称">'
			+ '<option value="" selected></option>'
			+ '<option value="联通" >联通</option>'
			+ '<option value="移动" >移动</option>'
			+ '<option value="电信" >电信</option>'
			+ '<option value="其他" >其他</option>'
			+ '</select>'
//			+ '<input type="text" class="form-control input-sm" name="coverList['+num+'].coverName" notEmpty notEmpty-value="覆盖业务链路类型/名称"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="coverList['+num+'].gbps" onblur="getSum(this.value)" notEmpty notEmpty-value="链路带宽(Gbps)"/>'
			+ '</td>'
			+ '<td>'
			+ '<div class="form-group">'
			+ '<label class="radio-inline">'
			+ '<input type="radio" name="coverList['+num+'].coverMode" value="0" style="display:none;" checked="checked" notEmpty notEmpty-value="覆盖方式">'
			+ '<input type="radio" name="coverList['+num+'].coverMode" value="1"> 并接'
			+ '</label>'
			+ '<label class="radio-inline">'
			+ '<input type="radio" name="coverList['+num+'].coverMode" value="2"> 串接'
			+ '</label>'
			+ '</div>'
			+ '</td>'
			+ '<td style="cursor:pointer" onclick="delTableTr('+trBodyId+')">'
			+ '<font style="color:red;" size="5">-</font>'
			+ '</td>'
			+ '</tr>';
		}
		
		var linkNum = $('input[name="linkNum"]').val();
		$('input[name="linkNum"]').val(++linkNum);
	} else if(type == 'node'){
		if(data != null){
			html += '<tr id="'+trBodyId+'">'
			+ '<td id="node_body_tr_td_'+num+'">'+(num+1)+'</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].province" notEmpty notEmpty-value="节点省份" value="'+data.province+'"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].city" notEmpty notEmpty-value="所属地市" value="'+data.city+'"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].name" notEmpty notEmpty-value="节点名称" value="'+data.name+'"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].address" notEmpty notEmpty-value="节点详细地址" value="'+data.address+'"/>'
			+ '</td>'
			+ '<td style="cursor:pointer" onclick="delTableTr('+trBodyId+')">'
			+ '<font style="color:red;" size="5">-</font>'
			+ '</td>'
			+ '</tr>';
		} else {
			html += '<tr id="'+trBodyId+'">'
			+ '<td id="node_body_tr_td_'+num+'">'+(num+1)+'</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].province" notEmpty notEmpty-value="节点省份"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].city" notEmpty notEmpty-value="所属地市"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].name" notEmpty notEmpty-value="节点名称"/>'
			+ '</td>'
			+ '<td>'
			+ '<input type="text" class="form-control input-sm" name="nodeList['+num+'].address" notEmpty notEmpty-value="节点详细地址"/>'
			+ '</td>'
			+ '<td style="cursor:pointer" onclick="delTableTr('+trBodyId+')">'
			+ '<font style="color:red;" size="5">-</font>'
			+ '</td>'
			+ '</tr>';
			
			var houseNum = $('input[name="houseNum"]').val();
			$('input[name="houseNum"]').val(++houseNum);
		}
	}
	
	$('#'+tbodyId).append(html);
	$('#'+tbodyId).attr('id-value', ++num);
	// 表格id排序
	reqTableTd(trBodyTdId);
}

//删除指定tr
function delTableTr(trBodyId){
	$(trBodyId).remove();
	var trBodyTdId = 'cname_body_tr_td_';
	if($(trBodyId).attr('id').indexOf('node_body_tr') > -1){
		trBodyTdId = 'node_body_tr_td_';
		var houseNum = $('input[name="houseNum"]').val();
		$('input[name="houseNum"]').val(--houseNum);
	}
	reqTableTd(trBodyTdId);
	getSum(1);
}

// 表格id 排序
function reqTableTd(trBodyTdId){
	var i = 1;
	$('td[id^='+trBodyTdId+']').each(function(){
		$(this).text(i);
		i++;
	});
}

function getSum(v){
	var isNum = jumpQuery(v);
	if(!isNum){
		return false;
	}
	var gbps = 0;
	$("input[name$='].gbps']").each(function(){
		gbps += parseInt($(this).val());
	});
	$('input[name="gbps"]').val(gbps);
}

function jumpQuery(v){
	if(v == ''){
		return ;
	}
	var isNum = false;
	//var reg = /^\+?[1-9][0-9]*$/;//判断是否为正整数 
	var reg =  /^[0-9]+.?[0-9]*$/;//判断是否为正数 
    var flag = reg.test($.trim(v));
    if(!flag){
    	layer.alert("请输入正数！", {
			icon : 3,
			offset: '100px'
		});
    	isNum = false
    } else {
    	isNum = true;
    }
    return isNum;
}

function valid(){
	$("input[name='code'").blur(function(){
		var check_name = "邮编";
		var check_value = $("input[name='code'").val();
		var reg = /^[0-9]{6}$/;
		check_field(reg,check_value,check_name);
	});
	$("input[name='tel'").blur(function(){
		var check_name = "固定电话";
		var check_value = $("input[name='tel'").val();
		var reg = /^(\d3,4|\d{3,4}-)?\d{7,8}$/;
		check_field(reg,check_value,check_name);
	});
	$("input[name='fax'").blur(function(){
		var check_name = "传真";
		var check_value = $("input[name='fax'").val();
		var reg = /^(\d{3,4}-)?\d{7,8}$/;
		check_field(reg,check_value,check_name);
	});
	$("input[name='moveTle'").blur(function(){
		var check_name = "移动电话";
		var check_value = $("input[name='moveTle'").val();
		var reg = /^1[34578]\d{9}$/;
		check_field(reg,check_value,check_name);
	});
	$("input[name='eMail'").blur(function(){
		var check_name = "电子邮件";
		var check_value = $("input[name='eMail'").val();
		var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
		check_field(reg,check_value,check_name);
	});
}

function check_field(reg,check_value,check_name){
	if(check_value == ''){
		layer.alert(check_name+"不能为空！", {icon : 3,offset: '100px'});
		return false;
	}
	if(!reg.test(check_value)){
		layer.alert("请填写正确的"+check_name+"！", {icon : 3,offset: '100px'});
		return false;
	}
	return true;
}

function upload1() {
	var singleTaskId = $('#singleTaskId').val();
	var url = "evalApplication/fileUpload";
	var options = {
		url : url,
		type : 'post',
		data : {
			'singleTaskId' : singleTaskId
		},
		dataType : "html",
		success : function(result) {
		},
		error : function(result) {
		}
	};
	$("#quertForm2").ajaxSubmit(options);
}

function filter(name){
	if(name == null || name == "null" || name == undefined){
		return "";
	}else{
		return name
	}
}